<template>
	<view>
		<view class="colonn">
			<view class="roww p-all-25">
				<view>盘点编号：</view>
				<view>{{pdOrder.pd_no}}</view>
			</view>
			<view class="roww p-all-25">
				<view>盘点状态：</view>
				<view>{{pdOrder.pd_status}}</view>
			</view>
			<view class="roww p-all-25 border_bottom">
				<input type="number" class="allline" v-model="tiaoma" placeholder="请输入编码" />
				<view @click.stop="getGoodInfoByNo">编码</view>
			</view>
			<view class="colonn p-all-25" v-if="goodInfo">
				<view>商品信息</view>
				<view class="h-20"></view>
				<view class="colonn">
					<view>商品名称：{{goodInfo.goodsName}}</view>
					<view class="h-20"></view>
					<input v-model="num" placeholder="请输入数量" />
					<view class="h-20"></view>
					<view @click.stop="updatePdNum">提交</view>
				</view>
			</view>
			<view class="h-100"></view>
			<view @click.stop="getChayi(1)">"提交盘点"</view>
			
			<view class="colonn">
				<view class="roww" v-for="(item,index) in pdGood">
					<view class="w-400">{{item.goodsName}}----</view>
					<view>{{item.num}}</view>
				</view>
			</view>
			
			<view class="colonn">
				<view class="roww" v-for="(item,index) in fpGood">
					<view class="w-400">{{item.goodsName}}----</view>
					<view>  <input placeholder="请输入数量" v-model="item.fp_num"  />  </view>
				</view>
				<view @click.stop="tuFupan">提交复盘数据</view>
			</view>
			
			
			
			
			
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tiaoma: "6925670811241",
				warehouseId: '1970325698298316032',
				goodInfo: null,
				cp_fp:1, //1是初盘2是复盘3是终盘
				num:0,
				// 待盘点商品
				pdGood:[],
				fpGood:[],//#复盘数据
			}
		},
		onLoad(options) {
			options.pdId = "2219967330596585856";
			this.pdOrder=uni.getStorageSync("pdOrder")
			this.getPdOrderInfo();
		},
		methods: {
			tuFupan(){
				var fpGood=this.fpGood;
				var ishave=true;
				for(var a=0;a<fpGood.length;a++){
					if(!fpGood[a].fp_num||fpGood[a].fp_num==''){
						ishave=false;
					}else{
						fpGood[a].fp_num=parseInt(fpGood[a].fp_num)
					}
				}
				if(!ishave){
					this.$tools.showToast("复盘数据未填写完成");
					return false;
				}
				var data={
					goodList:fpGood,
					'pd_id':this.pdOrder.pd_id
				}
				this.$axios
					.axios('post', this.$paths.addFpDate, data)
					.then((res) => {
						console.log("提交复盘数据结果",res);
					})
					.catch((err) => {
						console.log('错误回调', err);
				});
			},
			// 获取盘点单详情
			getPdOrderInfo(){
				var data = {
					"pdId":this.pdOrder.pd_id
				}
				this.$axios
					.axios('post', this.$paths.getPdOrderInfo, data)
					.then((res) => {
						this.pdOrder=res.data[0];
						this.$forceUpdate();
						if(this.pdOrder.pd_status==2){
							this.getChayi(1)
						}
					})
					.catch((err) => {
						console.log('错误回调', err);
				});
					
			},
			// 如果是初盘,去获取盘点差异数量
			toSubject(){
				if(this.cp_fp==1){
					this.getChayi()
				}else if(this.cp_fp==2){
					// 提交复盘数据
					this.toJieshou();
				}
			},
			// 将盘点数据进行提交
			toJieshou(){
				
			},
			
			addGoods(item){
				item['num']=this.num;
				console.log("aaa",item)
				this.pdGood.push(item);
				this.num=0;
			},
			// 获取差异订单
			getChayi(type){
				var data = {
					'warehouseId': this.pdOrder.warehouse_id,
					"pdId":this.pdOrder.pd_id
				}
				this.$axios
					.axios('post', this.$paths.getChayiGoods, data)
					.then((res) => {
						console.log("aa",res);
						console.log("需要复盘的商品",res);
						if(type&&type==1){
							this.fpGood=res.data;
						}
					})
					.catch((err) => {
						console.log('错误回调', err);
					});
			},
			
			// 通过条码查询商品
			getGoodInfoByNo() {
				var data = {
					'skuBarcode': this.tiaoma,
					'warehouseId': this.pdOrder.warehouse_id
				}
				this.$axios
					.axios('post', this.$paths.getGoodInfoByNo, data)
					.then((res) => {
						if (res.data && res.data.length > 0) {
							this.goodInfo = res.data[0];
						} else {
							this.$tools.showToast("酸奶");
						}
					})
					.catch((err) => {
						console.log('错误回调', err);
					});
			},
			// 修改商品数量
			updatePdNum() {
				if(!this.num){
					return false;
				}
				var data = {
					warehouseId: this.pdOrder.warehouse_id,
					skuBarcode:this.goodInfo.skuBarcode,
					pdId:this.goodInfo.pdId,
					num: this.num,
					type:this.cp_fp
				}
				this.$axios
					.axios('post', this.$paths.updatePdNum, data)
					.then((res) => {
						console.log(res)
						if(res.code==200){
							this.getGoodInfoByNo()
							this.addGoods(this.goodInfo);
						}else{
							this.$tools.showToast(res.msg);
						}
						
					})
					.catch((err) => {
						console.log('错误回调', err);
					});
			},

		}
	}
</script>

<style>

</style>